<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <button id="btn">获取当前位置</button>
    <p id="address"></p>
</body>

<script>
    let btn = document.getElementById("btn");
    let address = document.getElementById("address")
    btn.onclick = function(){
        // navigator.geolocation.getCurrentPosition方法，用于获取当前位置。3个参数，
        // 第一个是获取成功时的回调函数，第二个参数
        navigator.geolocation.getCurrentPosition(function(pos){
            address.texeContent =pos.coords.latitude+","+pos.coords.longitude;
            console.log("coor");
        },function(err){
            // console.log("获取失败");
            // console.log(err);
            alert("获取位置")
        },{
            timeout:10000
        });
    }

</script>
</html>